<template>
	<div class="padding-container preview-wrap">
    <el-dialog ref="dialog" :title="$root.lang.control.device.detail.log.operateLogtitle" :visible.sync="showDialog" width="70%" @close="closeDialog"  :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form class="tab-pan form-inline" size="small" label-position="right" label-width="120px">
        <el-form-item :label="$root.lang.control.device.detail.log.title + '：'">
          <span>{{ baseData.title | dataFormat }}</span>
        </el-form-item>
        <el-form-item :label="$root.lang.control.device.detail.log.appName + '：'">
          <span v-if="baseData.appInfo != null">{{ baseData.appInfo.appName | dataFormat }}</span>
          <span v-else-if="baseData.appInfo == null">{{ '--' }}</span>
        </el-form-item>
        <el-form-item :label="$root.lang.control.device.detail.log.appV + '：'">
          <span v-if="baseData.appInfo != null">{{ baseData.appInfo.appV | dataFormat }}</span>
          <span v-else-if="baseData.appInfo == null">{{ '--' }}</span>
        </el-form-item>
      </el-form>
      <el-form class="tab-pan form-inline" size="small" label-position="right" label-width="120px">
        <el-form-item :label="$root.lang.control.device.detail.log.operTime + '：'">
          <span>{{ baseData.operaData | dateFormat }}</span>
        </el-form-item>
        <el-form-item :label="$root.lang.control.device.detail.log.appIdentification + '：'">
          <span v-if="baseData.appInfo != null">{{ baseData.appInfo.appIdentification | dataFormat }}</span>
          <span v-else-if="baseData.appInfo == null">{{ '--' }}</span>
        </el-form-item>
        <el-form-item :label="$root.lang.control.device.detail.log.appSupplier + '：'">
          <span v-if="baseData.appInfo != null">{{ baseData.appInfo.appSupplier | dataFormat }}</span>
          <span v-else-if="baseData.appInfo == null">{{ '--' }}</span>
        </el-form-item>
      </el-form>
      <div class="title-part">
			  <span>{{ $root.lang.control.device.list.title }}</span>
      </div>
      <el-table
        v-loading="listLoading"
        :data="deviceList"
        :empty-text="$root.lang.control.device.list.noData"
        size="small"
        border
        style="width: 100%"
        >
        <el-table-column
          align="center"
          label="序号"
          width="100">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          :label="$root.lang.control.device.list.deviceName">
          <template slot-scope="scope">
            <span>{{ scope.row.deviceName | dataFormat }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          :label="$root.lang.control.device.list.IMEI">
          <template slot-scope="scope">
            <span>{{ scope.row.imei | dataFormat }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
	</div>
</template>

<script>
import '@/options/reportType'
export default {
	name: 'OperateLogDetail',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    uuid: {
      type: String,
      default: ''
    },
  },
  watch: {
    show: function (value) {
      this.showDialog = value
      if(value) {
        this.fetchData()
      }
    },
  },
	data() {
		return {
			listLoading: false,
      showDialog: this.show,
      tableData: [],
      tableTotal: 0,
      baseData: {
        title: null,
        operaData: null,
        appInfo: {},
      },
      deviceList: [],
		}
	},
  methods: {
    fetchData() {
      this.listLoading = false
      this.request({
          url: '/log/oper/batch/' + this.uuid,
          method: 'get',
        }).then(response => {
          this.baseData.title = response.result.title
          this.baseData.operaData = response.result.operaData
          this.baseData.appInfo = response.result.app
          this.deviceList = response.result.devices
          this.listLoading = false
        }).catch(error => {
          this.listLoading = false
          this.baseData = {}
          this.deviceList = []
          this.$message({
            message: error.errmsg,
            type: 'error',
            duration: 3 * 1000
          })
      })
    },
    closeDialog() {
      this.$emit('editReceive',{
        key: 'showLogDetail',
        value: this.showDialog
      })
    }
  },
  created() {
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
	.padding-container {
		text-align:left;
		.title-part {
			text-align: left;
			font-size: 15px;
			padding-bottom: 10px;
		}
    .form-inline {
			display: inline-block;
			vertical-align: top;
			min-width: 300px;
		}
	} 
</style>